/*
Package v1
@Time : 2022/12/21 17:28
@Author : 董胜烨
@File : overtime
@Software: GoLand
@note:
*/
package v1

import (
	"employee/service"
	"fmt"
	"github.com/gin-gonic/gin"
	"strconv"
)

func InsertOvertime(c *gin.Context) {
	overtime := &service.Overtime{}
	err := c.BindJSON(overtime)
	if err != nil {
		fmt.Println("InsertOvertime error:", err)
	}
	ok := overtime.Insert()
	if ok {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "插入成功",
		})
	} else {
		c.JSON(200, gin.H{
			"code": 1,
			"msg":  "插入失败",
		})
	}
}
func UpdateOvertime(c *gin.Context) {
	overtime := &service.Overtime{}
	err := c.BindJSON(overtime)
	if err != nil {
		fmt.Println("UpdateOvertime error:", err)
	}
	ok := overtime.Update()
	if ok {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "更新成功",
		})
	} else {
		c.JSON(200, gin.H{
			"code": 1,
			"msg":  "更新失败",
		})
	}
}
func DeleteOvertime(c *gin.Context) {
	overtime := &service.Overtime{}
	err := c.BindJSON(overtime)
	if err != nil {
		fmt.Println("InsertOvertime error:", err)
	}
	ok := overtime.Delete()
	if ok {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "删除成功",
		})
	} else {
		c.JSON(200, gin.H{
			"code": 1,
			"msg":  "删除失败",
		})
	}
}
func QueryOvertime(c *gin.Context) {
	overtime := &service.Overtime{}
	overtime.EmployeeID, _ = strconv.ParseInt(c.DefaultQuery("employee_id", "0"), 10, 64)
	res := overtime.QueryByEmployee()
	if res != nil {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "获取成功",
			"data": res,
		})
	} else {
		c.JSON(200, gin.H{
			"code": 1,
			"msg":  "获取失败",
		})
	}
}
